<!DOCTYPE html>
<html lang="en">
<head>
    <script src="/static/js/dev.js"></script>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!--bootstrap插件-->
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <link href="/static/plugin/bootstrap/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="/static/plugin/jo/joUI.css" rel="stylesheet"/>
    <!--字体插件-->
    <link href="/static/plugin/font-awesome-4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
    <link href="/static/plugin/layui-2.4.3/css/layui.css" rel="stylesheet"/>
    <!--ztree-->
    <link href="/static/plugin/zTree/css/metroStyle/metroStyle.css" rel="stylesheet"/>
    <!--common-->
    <link href="/static/css/common.css" rel="stylesheet"/>

    <title>代码生成主体信息表单</title>

    <style>
        /*#colList tr>td:nth-child(n+7){
            border-bottom: solid 2px #57C7D4;
        }
        #colList tr>td:nth-child(n+11){
            border-bottom: solid 2px #F96868;
        }*/
        #colList tr>th:nth-child(n+4){
            color: #62A8EA;
        }
        #colList tr>th:nth-child(n+8){
            color: #F96868;
        }
        .td-hover{
            background-color: #F4F4F4;
        }
        .extend-tag-option{
            line-height: 34px;
            font-weight: normal;
            display: inline-block;
            margin-right: 12px;
        }
    </style>
</head>
<body>
<div class="container-fluid">
    <div class="row">
        <div class="col-xs-12">
            <!--按钮栏-->
            <div class="form-group button-bar button-bar">
                <button type="button" isShow="joForm.isAdd" class="btn btn-primary" onclick="joForm.save()">
                    <i class="fa fa-plus-circle" aria-hidden="true"></i>&nbsp;新增
                </button>
                <button type="button" isShow="!joForm.isAdd" class="btn btn-info" onclick="joForm.update()">
                    <i class="fa fa-pencil-square" aria-hidden="true"></i>&nbsp;修改
                </button>
                <button type="button" isShow="!joForm.isAdd" class="btn btn-success" onclick="syncFieldChange()">
                    <i class="fa fa-refresh" aria-hidden="true"></i>&nbsp;同步字段变更
                </button>
                <button type="button" isShow="!joForm.isAdd" class="btn btn-danger" onclick="joForm.del()">
                    <i class="fa fa-trash" aria-hidden="true"></i>&nbsp;删除
                </button>
            </div>
            <!--按钮栏-->
        </div>
    </div>
    <div class="row">
        <div class="col-xs-12">

            <form id="pageForm" name="pageForm" action="" method="post">
                <div class="young-form-item col-sm-6 must">
                    <div class="young-form-label">数 据 表</div>
                    <div class="young-form-tips"></div>
                    <div class="young-form-input-block">
                        <select ErrEmpty="数据表不允许为空" onchange="tableChange(this.value)" id="tableName" name="tableName" class="joSelect form-control" data="" dataurl="{URL_CMS}cms/db/getTableList" keyfield="id" valuefield="id" firstitem='{"id":"","id":""}'></select>
                    </div>
                </div>
                <div class="young-form-item col-sm-6 must">
                    <div class="young-form-label">实体类名</div>
                    <div class="young-form-tips">
                        <span class="fa fa-info-circle" onmouseover="window.tipsIdx=jo.tips('建议将业务无关的前缀去掉',this,{tips:[2, '#3595CC'], time:10000});" onmouseout="jo.close(window.tipsIdx);"></span>
                    </div>
                    <div class="young-form-input-block">
                        <input type="text" id="className"  name="className" class="form-control " ErrEmpty="实体类名不允许为空" />
                    </div>
                </div>
                <div class="young-form-item col-sm-6 must">
                    <div class="young-form-label">表(类)注 释</div>
                    <div class="young-form-tips"></div>
                    <div class="young-form-input-block">
                        <input type="text"   name="tableRemark" class="form-control "  ErrEmpty="表注释不允许为空" />
                    </div>
                </div>
                <div class="young-form-item col-sm-6">
                    <div class="young-form-label">日志服务</div>
                    <div class="young-form-tips"></div>
                    <div class="young-form-input-block">
                        <select  name="logService" class="form-control ">
                            <option value="1">启用(Controller+Service)</option>
                            <option value="2">启用(仅Controller)</option>
                            <option value="0">不启用</option>
                        </select>
                    </div>
                </div>
                <div class="young-form-item col-sm-6 must">
                    <div class="young-form-label">包　　名</div>
                    <div class="young-form-tips"></div>
                    <div class="young-form-input-block">
                        <input type="text"   name="packageName" class="form-control " value="com.young" placeholder="例如: com.young" />
                    </div>
                </div>
                <div class="young-form-item col-sm-6 must">
                    <div class="young-form-label">模 块 名</div>
                    <div class="young-form-tips"></div>
                    <div class="young-form-input-block">
                        <input type="text" id="moduleName"  name="moduleName" class="form-control " value="" placeholder="例如: cms" />
                    </div>
                </div>
                <div class="young-form-item col-sm-6 must">
                    <div class="young-form-label">保存路径</div>
                    <div class="young-form-tips">
                        <span class="fa fa-info-circle" onmouseover="window.tipsIdx=jo.tips('生成的代码文件存放目录,请务必输入正确的文件夹路径',this,{tips:[2, '#3595CC'], time:10000});" onmouseout="jo.close(window.tipsIdx);"></span>
                    </div>
                    <div class="young-form-input-block">
                        <input type="text"   name="savePath" class="form-control" value="C:\youngCodeGenerate" placeholder="输入代码保存路径" />
                    </div>
                </div>
                <div class="young-form-item col-sm-6 must">
                    <div class="young-form-label">服务域名</div>
                    <div class="young-form-tips">
                        <span class="fa fa-info-circle" onmouseover="window.tipsIdx=jo.tips('web请求的域名地址,例如:http://ums.imrookie.cn/,可选择系统内置的域名常量',this,{tips:[2, '#3595CC'], time:10000});" onmouseout="jo.close(window.tipsIdx);"></span>
                    </div>
                    <div class="young-form-input-block">
                        <select  name="webDomain" class="form-control " ErrEmpty="服务域名不允许为空">
                            <option value=""></option>
                            <option value="/" selected="selected">/</option>
                            <option value="{contextPath}">{contextPath}</option>
                            <option value="{URL_UMS}">{URL_UMS}</option>
                            <option value="{URL_FS}">{URL_FS}</option>
                            <option value="{URL_CMS}">{URL_CMS}</option>
                            <option value="{URL_PORTAL}">{URL_PORTAL}</option>
                            <option value="{URL_MONITOR}">{URL_MONITOR}</option>
                            <option value="{URL_CONFIG}">{URL_CONFIG}</option>
                        </select>
                    </div>
                </div>

                <div class="young-form-item col-sm-6">
                    <div class="young-form-label">备　　注</div>
                    <div class="young-form-tips"></div>
                    <div class="young-form-input-block">
                        <input type="text" name="name" class="form-control "  placeholder="输入当前代码生成配置的说明信息" />
                    </div>
                </div>
                <div class="young-form-item col-sm-6">
                    <div class="young-form-label">作　　者</div>
                    <div class="young-form-tips"></div>
                    <div class="young-form-input-block">
                        <input type="text"   name="author" class="form-control"  placeholder="例如: imrookie" />
                    </div>
                </div>
                <div class="young-form-item col-sm-12">
                    <div class="young-form-label">其他功能</div>
                    <div class="young-form-tips"></div>
                    <div class="young-form-input-block" style="border: #cccccc dashed 1px;padding: 0px 5px;">
                        <label class="extend-tag-option"><input type="checkbox" name="extendTag" value="tag_import" class="default-checked-no">&nbsp;支持导入</label>
                        <label class="extend-tag-option"><input type="checkbox" name="extendTag" value="tag_export">&nbsp;支持导出</label>
                        <label class="extend-tag-option"
                               title="BaseDO模型中字段有：顺序、创建和更新时间、创建人和更新人、数据版本号、删除标识、排序等常用公共属性，详情请查看代码">
                            <input type="checkbox" name="extendTag" value="tag_BaseDO">&nbsp;继承BaseDO模型
                        </label>
                        <label class="extend-tag-option" title="新增和修改时在网关层填充相关基础字段属性，比如新增时赋值创建人信息等">
                            <input type="checkbox" name="extendTag" value="tag_fill_BaseDO">&nbsp;继承并自动填充BaseDO
                        </label>
                        <label class="extend-tag-option" title="继承DbSortDO的方式支持后端排序，不勾选则默认在模型类中添加排序字段">
                            <input type="checkbox" name="extendTag" value="tag_DbSortDO">&nbsp;继承DbSortDO
                        </label>
                    </div>
                </div>
            </form>

        </div>
    </div>

    <div class="row">
        <div class="col-xs-12">
            <!--字段配置信息-->
            <div class="table-responsive">
                <table class="table table-bordered table-hover table-line-auto table-header-style" id="colList" trHandle="formatControls">
                    <col field="_seq" title="#" width="5%" align="center"/>
                   <!-- <col field="id" title="主键" width="15%" align="" event="click"/>
                    <col field="genId" title="代码生成编号" width="15%" align=""/>-->
                    <col field="字段：{fieldName}<br>类型：{fieldTypeShow}" title="表字段" width="20%" align="left" headAlign="left"/>
                    <col field="{attrName} {fieldRemark}" title="Java属性&注释" width="20%" align=""/>
<!--                    <col field="fieldRemark" title="字段描述" width="18%" align=""/>-->
<!--                    <col field="{fieldType} ( {fieldLength} )" title="字段类型" width="21%" align="left" headAlign="left"/>-->
                    <!--<col field="fieldLength" title="字段长度" width="10%" align="right" headAlign="right"/>-->
                    <!--<col field="fieldNotNull" title="字段非空" width="10%" align=""/>-->
                    <col field="viewShow" title="视图显示" width="8%" align="center"/>
                    <col field="viewNum" title="视图顺序" width="8%" align=""/>
                    <col field="asCondition" title="检索条件" width="10%" align=""/>
                    <col field="supportSort" title="支持排序" width="8%" align="center"/>
                    <col field="formShow" title="表单显示" width="8%" align="center"/>
                    <col field="formNum" title="表单顺序" width="8%" align=""/>
                    <col field="{controlType}{controlParam}" title="控件类型" width="18%" align=""/>
                    <!--<col field="controlParam" title="控件参数" width="15%" align=""/>-->
                    <col field="controlMust" title="必填" width="8%" align="center"/>
                    <col field="controlReadonly" title="只读" width="10%" align=""/>
                    <col field="{controlCheck}{controlCheckVal}" title="表单验证" width="15%" align=""/>
                    <col field="{controlDefault} {fillExplain}" title="默认值&tips" width="15%" align=""/>

                    <!--<col field="controlCheckVal" title="验证值" width="10%" align=""/>-->
<!--                    <col field="fillExplain" title="表单tips" width="20%" align=""/>-->
<!--                    <col field="controlClass" title="表单样式" width="12%" align=""/>-->
                </table>
            </div>
        </div>
    </div>
</div>

<!--配置信息-->
<script src="/static/js/config.js"></script>
<!--jquery-->
<script src="/static/plugin/jquery/jquery-3.3.1.js"></script>
<script src="/static/plugin/jquery/jquery.cookie.js"></script>
<!--bootstrap-->
<script src="/static/plugin/bootstrap/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<!--[if lt IE 9]>
<script src="/static/plugin/other/html5shiv.js"></script>
<script src="/static/plugin/other/respond.min.js"></script>
<![endif]-->
<!--layui-->
<script src="/static/plugin/layui-2.4.3/layui.all.js"></script>
<!--ztree-->
<script src="/static/plugin/zTree/js/jquery.ztree.all.js"></script>
<!--common-->
<script src="/static/js/common.js"></script>
<!--jo-->
<script src="/static/plugin/jo/jo.js"></script>
<script src="/static/plugin/jo/jo-adapt.js"></script>
<script src="/static/plugin/jo/jo-page-view.js"></script>
<script src="/static/plugin/jo/jo-page-form.js"></script>
<script src="/static/plugin/jo/jo-listener.js"></script>
<script type="text/javascript">

    $(function(){
        var jParams = {
            "PKName" : "id",//主键属性名
            "saveAfter" : "toEdit",
            "addUrl" : "{URL_CMS}cms/genMain/insert",//新增
            "deleteUrl" : "{URL_CMS}cms/genMain/delete",//删除
            "updateUrl" : "{URL_CMS}cms/genMain/update",//修改
            "formDataUrl" : "{URL_CMS}cms/genMain/get"	//查询
        };
        joForm.initFormPage(jParams);//初始化

        //表格悬停处理
        $("#colList").on('mouseover', 'td', function(event){//td-hover
            var idx = $(this).index();
            $("#colList tr").find("td").removeClass("td-hover");
            $("#colList tr").find("td:eq("+idx+")").addClass("td-hover");
        });

    });
    //新增和修改前对数据处理
    joForm.dealDataAtSaveBefore = joForm.dealDataAtUpdateBefore = function(obj){
        var trs = $("#colList>tbody").find("tr");
        var cols = [];
        for(var i=0;i<trs.length;i++){
            var col = parseInput2Json($(trs[i]));
            //写死样式为2, 1已经太久没用了, 废弃掉
            col.controlClass = 2;
            cols.push(col);
        }
        obj.cols = jo.obj2JsonStr(cols);
        // 扩展标记啥也没选的话,默认为空字符串,避免更新不了
        if (!obj.extendTag) {
            obj.extendTag = '';
        }
    };
    //解析控件
    function parseInput2Json(obj){
        var res = {};
        var arr = $(obj).find('input');
        for(var i=0;i<arr.length;i++){
            if(arr[i].type == "checkbox"){//勾选框,通过判断是否选中设置值
                if(arr[i].checked){
                    res[arr[i].name] = '1';
                }else{
                    res[arr[i].name] = '0';
                }
            }else{
                res[arr[i].name] = arr[i].value;
            }
        }
        arr = $(obj).find('textarea');
        for(var i=0;i<arr.length;i++){
            res[arr[i].name] = arr[i].value;
        }
        arr = $(obj).find('select');
        for(var i=0;i<arr.length;i++){
            res[arr[i].name] = arr[i].value;
        }
        arr = $(obj).find('span');
        for(var i=0;i<arr.length;i++){
            res[$(arr[i]).attr("name")] = $(arr[i]).attr("value");
        }
        return res;
    }
    //新增初始化
    joForm.initFormPageOfAdd = function(){
        var m = '';
        if(m){
            $("#moduleName").val(m);
        }
        // 默认选中
        $('.default-checked').attr('checked', true);
    };
    //初始化表单值前处理
    joForm.initFormValueBefore = function(oJson){
    };
    //初始化表单后
    joForm.initFormValueAfter = function(oJson){
        //加载字段配置
        if(joForm.params.PKValue){
            loadColList();
        }
        $("#tableName").attr("disabled", true);//禁止改变数据表
    };
    // 加载字段配置列表
    function loadColList() {
        jo.postAjax("{URL_CMS}cms/genCol/getList", {"genId":joForm.params.PKValue}, function(json){
            if(json && json.code == "0"){
                jo.sort(json.data, function(a, b){
                    return a.viewNum < b.viewNum;
                });
                Grid("colList").loadData(json.data);
            }
        }, true);
    }
    //数据表改变事件
    function tableChange(tableName){
        if(joForm.isAdd && tableName){//新增页时才允许切换数据表
            if(tableName.indexOf('tb_') == 0 || tableName.indexOf('TB_') == 0){
                $("#className").val(wordOne2Up(up2Tuo(tableName.substring(3))));
            }else{
                $("#className").val(wordOne2Up(up2Tuo(tableName)));
            }
            jo.postAjax("{URL_CMS}cms/db/getColumsByTableName", {"tableName":tableName}, function(json){
                if(json && json.code == "0"){
                    for(var i=0;i<json.data.length;i++){
                        var item = json.data[i];
                        item.fieldName = item.field;
                        item.fieldRemark = item.remark;
                        item.fieldType = item.type;
                        item.fieldLength = item.length;
                        item.fieldNotNull = item.notNull;
                        item.formNum = (i+1)*10;
                        item.viewNum = (i+1)*10;
                        item.attrName = up2Tuo(item.fieldName);
                        if(item.fieldLength && item.fieldLength > 2000){//字段长度较长的默认不在视图显示,默认使用大文本框
                            item.viewShow = '0';
                            item.controlType = 'textarea';
                        }else{
                            item.viewShow = 1;
                        }
                        item.formShow = 1;
                    }
                    jo.sort(json.data, function(a, b){
                        return a.viewNum < b.viewNum;
                    });
                    Grid("colList").loadData(json.data);
                }
            });
        }else{
            $("#className").val('');
            Grid("colList").loadData([]);
        }
    }
    //控件类型选项
    var options_controlType = [
        {value:'input', text:'输入框(input)'}
        ,{value:'joInput', text:'输入下拉框(带提示的input)'}
        ,{value:'date', text:'日期选择'}
        ,{value:'select', text:'下拉选择(select)'}
        ,{value:'joSelect', text:'jo下拉选择'}
        ,{value:'textarea', text:'大文本框(textarea)'}
        ,{value:'radio', text:'单选(radio)'}
        ,{value:'checkbox', text:'多选(checkbox)'}
        ,{value:'tree', text:'树选择(单选)'}
        ,{value:'trees', text:'树选择(多选)'}
        ,{value:'list', text:'列表选择(单选)'}
        ,{value:'lists', text:'列表选择(多选)'}
        ,{value:'label', text:'文字'}
    ];
    //控件只读处理选项
    var options_controlReadonly = [
        {value:'none', text:'无'}
        ,{value:'add', text:'新增时只读'}
        ,{value:'edit', text:'编辑时只读'}
        ,{value:'all', text:'总是只读'}
    ];
    //控件样式选项
    var options_controlClass = [
        {value:'2', text:'表单v2'}
        ,{value:'1', text:'表单v1'}
    ];
    //表单验证选项
    var options_controlCheck = [
        {value:'', text:''}
        ,{value:'ErrEmpty', text:'非空验证'}
        ,{value:'ErrLength', text:'长度验证'}
        ,{value:'ErrNumber', text:'数字类型验证'}
        ,{value:'ErrMail', text:'邮箱验证'}
        ,{value:'ErrPhone', text:'手机号验证'}
        ,{value:'ErrReg', text:'自定义正则验证'}
    ];
    //检索条件
    var options_asCondition = [
        {value:'1', text:'否'}
        ,{value:'2', text:'=查询'}
        ,{value:'3', text:'like查询'}
    ];
    //格式化控件,将数据转为表单元素
    function formatControls(item, idx){



        item.attrName = val2Control(item.attrName, "attrName", "input", 'java属性名,必填');

        item.viewShow = val2Control(item.viewShow, "viewShow", "checkbox");
        item.supportSort = val2Control(jo.getDefVal(item.supportSort, '0'), "supportSort", "checkbox");
        item.viewNum = val2Control(item.viewNum, "viewNum", "input");
        //主键默认作为检索条件
        if(item.fieldName.toUpperCase() == "ID"){
            item.asCondition = val2Control(jo.getDefVal(item.asCondition, '2'), "asCondition", "select", options_asCondition);
        }else{
            item.asCondition = val2Control(item.asCondition, "asCondition", "select", options_asCondition);
        }

        item.formShow = val2Control(item.formShow, "formShow", "checkbox");
        item.controlMust = val2Control(jo.getDefVal(item.controlMust, jo.getDefVal(item.fieldNotNull, '0')), "controlMust", "checkbox", null, "mustChecked");
        item.formNum = val2Control(item.formNum, "formNum", "input");
        if(item.controlType == 'joSelect' || item.controlType == 'tree' || item.controlType == 'trees' || item.controlType == 'list' || item.controlType == 'lists'){
            item.controlParam = val2Control(item.controlParam, "controlParam", "input", '控件参数(URL等)');
        }else if(item.controlType == 'select'){
            item.controlParam = val2Control(item.controlParam, "controlParam", "input", '格式:k1:v1,k2:v2');
        }else if(item.controlType == 'joInput'){
            item.controlParam = val2Control(item.controlParam, "controlParam", "input", '格式:val1,val2,val3');
        }else{
            item.controlParam = '<input type="text" name="controlParam" placeholder="控件参数(URL,格式化参数等)" value="'+jo.getDefVal(item.controlParam, '')+'" class="form-control input-sm" style="padding-left:4px;padding-right:4px;display:none;">';
        }
        item.controlDefault = val2Control(item.controlDefault, "controlDefault", "input", '默认值');
        //时间类型则默认使用日期控件
        if(item.fieldType.indexOf("date") > -1 || item.fieldType.indexOf("DATE") > -1
                || item.fieldType.indexOf("time") > -1 || item.fieldType.indexOf("TIME") > -1){
            item.controlType = val2Control(jo.getDefVal(item.controlType, 'date'), "controlType", "select", options_controlType, 'controlTypeChange');
        }else if(item.fieldType.indexOf("text") > -1 || item.fieldType.indexOf("TEXT") > -1
                || item.fieldType.indexOf("clob") > -1 || item.fieldType.indexOf("CLOB") > -1 ){
            item.controlType = val2Control(jo.getDefVal(item.controlType, 'textarea'), "controlType", "select", options_controlType, 'controlTypeChange');
        }else{
            item.controlType = val2Control(item.controlType, "controlType", "select", options_controlType, 'controlTypeChange');
        }
        item.controlReadonly = val2Control(jo.getDefVal(item.controlReadonly, ((item.fieldName == 'id' || item.fieldName == 'ID') ? 'edit' : '')), "controlReadonly", "select", options_controlReadonly);
        // item.controlClass = val2Control(item.controlClass, "controlClass", "select", options_controlClass);

        //数字类型默认进行数字验证
        if(item.fieldType.indexOf("number") > -1 || item.fieldType.indexOf("NUMBER") > -1
                || item.fieldType.indexOf("int") > -1 || item.fieldType.indexOf("INT") > -1
                || item.fieldType.indexOf("float") > -1 || item.fieldType.indexOf("FLOAT") > -1
                || item.fieldType.indexOf("double") > -1 || item.fieldType.indexOf("DOUBLE") > -1 ){
            if(joForm.isAdd){//新增时才进行验证默认值设置
                item.controlCheck = jo.getDefVal(item.controlCheck, 'ErrNumber');
            }
        }

        //默认非空字段使用非空验证
        if(joForm.isAdd){//新增时才进行验证默认值设置
            item.controlCheck = jo.getDefVal(item.controlCheck, (item.fieldNotNull == '1' ? 'ErrEmpty' : ''));
        }
        item.controlCheckVal = jo.getDefVal(item.controlCheckVal, getTipByCheckType(item.controlCheck, item.fieldRemark));
        //表单验证有效,则显示验证值
        if(item.controlCheck){
            item.controlCheckVal = val2Control(item.controlCheckVal, "controlCheckVal", "input", '验证值(可以为空)');
        }else{
            item.controlCheckVal = '<input type="text" name="controlCheckVal" placeholder="验证值(可以为空)" value="'+jo.getDefVal(item.controlCheckVal, '')+'" class="form-control input-sm" style="padding-left:4px;padding-right:4px;display:none;">';
        }
        item.controlCheck = val2Control(item.controlCheck, "controlCheck", "select", options_controlCheck, 'controlCheckChange');

        item.fieldRemark = val2Control(item.fieldRemark, "fieldRemark", "input", '字段说明');
        //固定值格式化为span标签,方便数据收集
        item.fieldName = val2Control(item.fieldName, 'fieldName', 'span', ((item.fieldNotNull == '1') ? 'font-red' : '') )
                + '<input type="hidden" name="id" value="'+item.id+'">' +
                '<input type="hidden" name="genId" value="'+item.genId+'"><input type="hidden" name="fieldNotNull" value="'+item.fieldNotNull+'">';
        item.fieldType = val2Control(item.fieldType, 'fieldType', 'span');
        item.fieldLength = val2Control(item.fieldLength, 'fieldLength', 'span');
        //字段类型显示文案
        item.fieldTypeShow = item.fieldType + ( item.fieldLength ? '('+item.fieldLength+')' : '' );

        item.fillExplain = val2Control(item.fillExplain, 'fillExplain', 'textarea', '表单字段说明');
        //item.fieldNotNull = val2Control(item.fieldNotNull, 'fieldNotNull', 'span');
    }
    //根据表单验证类型返回提示语
    function getTipByCheckType(controlCheck, remark){
        var tip = '';
        if(remark && remark.indexOf(',') > -1){
            remark = remark.split(',')[0];
        }
        if(controlCheck == 'ErrEmpty'){
            tip = jo.getDefVal(remark, '') + '不允许为空';
        }else if(controlCheck == 'ErrLength'){//使用默认提示
            //tip = jo.getDefVal(remark, '') + '长度过长';
        }else if(controlCheck == 'ErrNumber'){
            tip = jo.getDefVal(remark, '') + '需填写数字类型';
        }
        return tip;
    }
    /**
     * 值转表单控件
     * @param val 值
     * @param name 控件name属性
     * @param type 控件类型
     * @param options select控件的备选项,[{value:x,text:y}..]; 控件类型为input/textarea时,表示placeholder提示; 控件类型为span时,表示class样式;
     * @param onchange select/checkbox控件的onchange事件函数名
     */
    function val2Control(val, name, type, options, onchange){
        var _html = '';
        if(type == "input"){
            _html = '<input type="text" name="'+name+'" value="'+jo.getDefVal(val, '')+'" placeholder="'+jo.getDefVal(options, '')+'" class="form-control input-sm" style="padding-left:4px;padding-right:4px;" autocomplete="off">';
        }else if(type == "checkbox"){
            _html = '<input type="checkbox" name="'+name+'" value="1" '+(val != '0' ? 'checked' : '')+' '+(onchange ? 'onchange="'+onchange+'(this)"' : '')+' style="width:14px;height:14px;">';
        }else if(type == "select"){
            val = jo.getDefVal(val, '');
            _html = '<select name="'+name+'" class="form-control input-sm" value="'+val+'" '+(onchange ? 'onchange="'+onchange+'(this)"' : '')+' style="padding-left:2px;padding-right:2px;">';
            for(var i =0;i<options.length;i++){
                if(val && options[i].value == val){
                    _html += '<option value="'+options[i].value+'" selected="selected">'+options[i].text+'</option>';
                }else{
                    _html += '<option value="'+options[i].value+'">'+options[i].text+'</option>';
                }
            }
            _html += '</select>';
        }else if(type == "span"){
            val = jo.getDefVal(val, '');
            _html = '<span name="'+name+'" value="'+val+'" class="'+jo.getDefVal(options, '')+'">'+val+'</span>';
        }else if(type == "textarea"){
            _html = '<textarea rows="1" name="'+name+'" placeholder="'+jo.getDefVal(options, '')+'" class="form-control input-sm" style="padding-left:4px;padding-right:4px;" autocomplete="off">'+jo.getDefVal(val, '')+'</textarea>';
        }
        return _html;
    }
    //控件类型选择
    function controlTypeChange(obj){
        if(obj && (obj.value == 'tree' || obj.value == 'trees' || obj.value == 'list' || obj.value == 'lists')){
            $(obj).next("input[name='controlParam']").attr('placeholder', '控件参数(URL,格式化参数等)');
            $(obj).next("input[name='controlParam']").show();
        }else if(obj && obj.value == 'select'){
            $(obj).next("input[name='controlParam']").attr('placeholder', '控件参数,格式:k1:v1,k2:v2');
            $(obj).next("input[name='controlParam']").show();
        }else if(obj && obj.value == 'joSelect'){
            $(obj).next("input[name='controlParam']").attr('placeholder', '控件参数:数据源URL');
            $(obj).next("input[name='controlParam']").show();
        }else if(obj && obj.value == 'joInput'){
            $(obj).next("input[name='controlParam']").attr('placeholder', '控件参数,格式:val1,val2,val3');
            $(obj).next("input[name='controlParam']").show();
        }else{
            $(obj).next("input[name='controlParam']").hide();
        }
    }
    //表单验证选择
    function controlCheckChange(obj){
        if(obj && obj.value){
            $(obj).next("input[name='controlCheckVal']").show();
            $(obj).next("input[name='controlCheckVal']").val(getTipByCheckType(obj.value, $(obj).parent().parent().find("input[name='fieldRemark']").val()));
        }else{
            $(obj).next("input[name='controlCheckVal']").hide();
        }
    }
    //是否必填复选框选择事件
    function mustChecked(obj){
        if(obj.checked){//必填项
            var o = $(obj).parent().parent().find("select[name='controlCheck']");
            if(o && o.val() == ""){//没有选择表单验证,自动改为非空验证
                o.val("ErrEmpty");
            }
        }else{
            var o = $(obj).parent().parent().find("select[name='controlCheck']");
            if(o && o.val() == "ErrEmpty"){//已设置过非空验证,则清空
                o.val("");
            }
        }
    }
    //大写格式转驼峰,首字母小写
    function up2Tuo(str){
        if(jo.isValid(str)){
            var arr = str.split("_");
            if(arr.length > 1){
                var s = arr[0].toLowerCase();
                for(var i=1;i<arr.length;i++){
                    s += arr[i].substring(0,1).toUpperCase() + arr[i].substring(1).toLowerCase();
                }
                return s;
            }else{
                return str.toLowerCase();
            }
        }else{
            return "";
        }
    }
    //单词首字母大写
    function wordOne2Up(str){
        return str.substring(0,1).toUpperCase() + str.substring(1);
    }
    //单词首字母小写
    function wordOne2Low(str){
        return str.substring(0,1).toLowerCase() + str.substring(1);
    }

    // 同步字段变更
    function syncFieldChange(){
        if (joForm.params.PKValue) {
            jo.confirm('确定要同步数据库字段变更嘛?', function (idx){
                jo.postAjax('/cms/genMain/syncFieldChange', {genId: joForm.params.PKValue}, function (json) {
                    if (json && json.code == 0) {
                        jo.showSuccessMsg('同步成功~');
                        // 刷新字段配置
                        loadColList();
                    } else {
                        jo.showErrorMsg(jo.getDefVal(json.info, '同步失败!'));
                    }
                }, true);
                jo.close(idx);
            });
        }

    }
</script>

</body>
</html>
